﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
                    xmlns:chronos="http://chronos/schemas/2010/xaml">

    <!-- Global Settings-->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
        <ResourceDictionary Source="Brushes.xaml"/>
        <ResourceDictionary Source="Fonts.xaml"/>
        <ResourceDictionary Source="CoreStyles.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    <!--Converters-->
    <chronos:StringToStyleConverter x:Key="StringToStyleConverter" />
   
    <!--Shortcut style-->
    <Style TargetType="{x:Type chronos:ShortcutElement}">
        <Setter Property="Id" Value="{Binding Id}"/>
        <Setter Property="Foreground" Value="{StaticResource ShortcutTextBrush}" />
        <Setter Property="FontFamily" Value="{StaticResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{StaticResource ShortcutFontSize}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="CanResize" Value="False" />
        <Setter Property="ConstraintToParent" Value="True" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="AllowDrop" Value="False" />
        <Setter Property="Width" Value="{x:Static SystemParameters.IconGridWidth}" />
        <Setter Property="Height" Value="{x:Static SystemParameters.IconGridHeight}" />
        <Setter Property="AllowDrop" Value="False" />
        <Setter Property="ContextMenu">
            <Setter.Value>
                <ContextMenu HasDropShadow="True">
                    <MenuItem Header="Abrir ..." Command="{Binding OpenCommand}"/>
                    <MenuItem Header="Eliminar" Command="{Binding CloseCommand}"/>
                    <Separator/>
                    <MenuItem Header="Agrupar" Command="{x:Static chronos:Desktop.GroupCommand}" />
                </ContextMenu>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type chronos:ShortcutElement}">
                    <Grid Background="Transparent"
                          Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                        
                        <Border x:Name="PART_Dragger" 
                                CornerRadius="3" 
                                BorderThickness="2"
                                Opacity="0"
                                BorderBrush="#FF7AA3D4"
                                Background="#FFC5D5E9">
                            <Border.InputBindings>
                                <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding OpenCommand}" />
                            </Border.InputBindings>
                        </Border>                            

                        <Grid IsHitTestVisible="False" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="3.5">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <Border x:Name="ShortcutIcon" 
                                    Grid.Row="0"
                                    HorizontalAlignment="Center" VerticalAlignment="Top" Margin="3.5">
                                <Path Fill="{TemplateBinding Foreground}"
                                      Height="22" Width="34" 
                                      Style="{Binding IconStyle, Converter={StaticResource StringToStyleConverter}}"/>
                            </Border>
                            
                            <TextBlock x:Name="ShortcutTitle" 
                                       Grid.Row="1"
                                       FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}"
                                       Text="{Binding Title}" 
                                       IsHitTestVisible="False"
                                       HorizontalAlignment="Center" VerticalAlignment="Top"
                                       TextAlignment="Center" TextWrapping="Wrap" />
                        </Grid>
                    </Grid>
                    
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_Dragger" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsActive" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.90" />
                        </MultiTrigger>
                        
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_Dragger" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsActive" Value="false" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.40" />
                        </MultiTrigger>
                        
                        <Trigger Property="IsActive" Value="True">
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.80" />
                        </Trigger>

                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.80" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <!--Shortcut Group style-->
    <Style TargetType="{x:Type chronos:ShortcutGroupElement}">
        <Setter Property="Id" Value="{Binding Id}"/>
        <Setter Property="Foreground" Value="{StaticResource ShortcutTextBrush}" />
        <Setter Property="FontFamily" Value="{StaticResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{StaticResource ShortcutFontSize}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="CanResize" Value="False" />
        <Setter Property="ConstraintToParent" Value="True" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="AllowDrop" Value="False" />
        <Setter Property="Width" Value="{x:Static SystemParameters.IconGridWidth}" />
        <Setter Property="Height" Value="{x:Static SystemParameters.IconGridHeight}" />
        <Setter Property="AllowDrop" Value="False" />
        <Setter Property="ContextMenu">
            <Setter.Value>
                <ContextMenu HasDropShadow="True">
                    <MenuItem Header="Eliminar" Command="{Binding CloseCommand}"/>
                </ContextMenu>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type chronos:ShortcutGroupElement}">
                    <Grid x:Name="Root" Background="Transparent"
                          Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">

                        <Border x:Name="PART_Dragger" 
                                CornerRadius="3" 
                                BorderThickness="2"
                                Opacity="0"
                                BorderBrush="#FF7AA3D4"
                                Background="#FFC5D5E9">
                        </Border>

                        <Grid IsHitTestVisible="False" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="3.5">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <Border x:Name="ShortcutIcon" 
                                    Grid.Row="0"
                                    HorizontalAlignment="Center" VerticalAlignment="Top" Margin="3.5">
                                <Path Fill="{TemplateBinding Foreground}"
                                      Height="22" Width="34" 
                                      Style="{Binding IconStyle, Converter={StaticResource StringToStyleConverter}}"/>
                            </Border>

                            <TextBlock x:Name="ShortcutTitle" 
                                       Grid.Row="1"
                                       FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}"
                                       Text="{Binding Title}" 
                                       IsHitTestVisible="False"
                                       HorizontalAlignment="Center" VerticalAlignment="Top"
                                       TextAlignment="Center" TextWrapping="Wrap" />
                        </Grid>

                        <Popup x:Name="ShortcutsView" 
                               AllowsTransparency="True"
                               Focusable="True" StaysOpen="True"
                               Placement="Top" PlacementTarget="{Binding ElementName=Root}" 
                               PopupAnimation="Slide">

                            <Border Margin="5" Effect="{StaticResource DropShadowBrush}" 
                                    Background="{StaticResource WindowBackgroundBrush}"
                                    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                    ScrollViewer.VerticalScrollBarVisibility="Auto">
                                <ItemsControl ItemsSource="{Binding Shortcuts}" Margin="20">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <UniformGrid />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Background="Transparent"
                                                  Margin="5"
                                                  Width="{x:Static SystemParameters.IconGridWidth}"
                                                  Height="{x:Static SystemParameters.IconGridHeight}">
                                                <Border x:Name="PART_Dragger" 
                                                        CornerRadius="3" 
                                                        BorderThickness="2"
                                                        Opacity="0"
                                                        BorderBrush="#FF7AA3D4"
                                                        Background="#FFC5D5E9">
                                                    <Border.InputBindings>
                                                        <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding OpenCommand}" />
                                                    </Border.InputBindings>
                                                </Border>

                                                <Grid IsHitTestVisible="False" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="3.5">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="40" />
                                                        <RowDefinition Height="*" />
                                                    </Grid.RowDefinitions>

                                                    <Border x:Name="ShortcutIcon" 
                                                            Grid.Row="0"
                                                            HorizontalAlignment="Center" VerticalAlignment="Top" Margin="3.5">
                                                        <Path Fill="{StaticResource ShortcutTextBrush}"
                                                              Height="22" Width="34" 
                                                              Style="{Binding IconStyle, Converter={StaticResource StringToStyleConverter}}"/>
                                                    </Border>

                                                    <TextBlock x:Name="ShortcutTitle" 
                                                               Grid.Row="1"
                                                               FontFamily="{StaticResource ContentFontFamily}" FontSize="{StaticResource ShortcutFontSize}" Foreground="{StaticResource ShortcutTextBrush}"
                                                               Text="{Binding Title}" 
                                                               IsHitTestVisible="False"
                                                               HorizontalAlignment="Center" VerticalAlignment="Top"
                                                               TextAlignment="Center" TextWrapping="Wrap" />
                                                </Grid>
                                            </Grid>    
                                            <DataTemplate.Triggers>
                                                <MultiTrigger>
                                                    <MultiTrigger.Conditions>
                                                        <Condition SourceName="PART_Dragger" Property="IsMouseOver" Value="True" />
                                                    </MultiTrigger.Conditions>
                                                    <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.90" />
                                                </MultiTrigger>
                                            </DataTemplate.Triggers>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </Border>
                        </Popup>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_Dragger" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsActive" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.90" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_Dragger" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsActive" Value="false" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.40" />
                        </MultiTrigger>

                        <Trigger Property="IsActive" Value="True">
                            <Setter TargetName="PART_Dragger" Property="Opacity" Value="0.80" />
                        </Trigger>

                        <Trigger Property="IsActive" Value="False">
                            <Setter TargetName="ShortcutsView" Property="IsOpen" Value="False" />
                        </Trigger>

                        <EventTrigger RoutedEvent="Deactivated">
                            <BeginStoryboard>
                                <Storyboard>
                                    <BooleanAnimationUsingKeyFrames Storyboard.TargetName="ShortcutsView"
                                                                    Storyboard.TargetProperty="IsOpen"
                                                                    Duration="0:0:0">
                                        <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0" />
                                    </BooleanAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>

                        <EventTrigger RoutedEvent="MouseDoubleClick">
                            <BeginStoryboard>
                                <Storyboard>
                                    <BooleanAnimationUsingKeyFrames Storyboard.TargetName="ShortcutsView"
                                                                    Storyboard.TargetProperty="IsOpen"
                                                                    Duration="0:0:0">
                                        <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
                                    </BooleanAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
